<!DOCTYPE html>
<html>
    <head>
        <!-- 页面meta -->
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>管理系统</title>
        <meta name="description" content="管理系统">
        <meta name="keywords" content="管理系统">
        <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
        <!-- 引入样式 -->
        <link rel="stylesheet" href="../plugins/elementui/index.css">
        <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
        <link rel="stylesheet" href="../css/style.css">
        <!-- 引入组件库 -->
        <script type="text/javascript" src="../js/jquery.min.js"></script>
        <script src="../js/vue.js"></script>
        <script src="../plugins/elementui/index.js"></script>
        <script src="../js/axios-0.18.0.js"></script>
        <script src="../plugins/echarts/echarts.js"></script>
        <style>
            .datatable {
                position: relative;
                box-sizing: border-box;
                -webkit-box-flex: 1;
                width: 100%;
                max-width: 100%;
                font-size: 14px;
                color: rgb(96, 98, 102);
                overflow: hidden;
                flex: 1 1 0%;
            }
            .datatable td, .datatable th {
                padding: 12px 0;
                min-width: 0;
                -webkit-box-sizing: border-box;
                box-sizing: border-box;
                text-overflow: ellipsis;
                vertical-align: middle;
                position: relative;
                text-align: left;
            }
        </style>
    </head>
    <body class="hold-transition">
        <div id="app">
            <div class="content-header">
                <h1>管理<small>管理</small></h1>
                <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
                    <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
                    <el-breadcrumb-item>管理</el-breadcrumb-item>
                    <el-breadcrumb-item>管理</el-breadcrumb-item>
                </el-breadcrumb>
            </div>
            <div class="app-container">
                <div class="box">
                    <div class="filter-container">
                        <el-input placeholder="名称/类别" v-model="pagination.queryString" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter"></el-input>
                        <el-button @click="findPage()" class="dalfBut">查询</el-button>
                        <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
                        <el-button type="primary" class="butT" @click="countBank()">统计-柱状图</el-button>
                        <el-button type="primary" class="butT" @click="exportExcel()">导出Excel</el-button>
                    </div>
                    <div class="boxMain">
                        <el-upload action="/two/importData.do"
                                   name="excelFile"
                                   :show-file-list="false"
                                   :on-success="handleSuccess"
                                   :before-upload="beforeUpload">
                            <el-button type="primary">导入</el-button>
                        </el-upload>
                    </div>
                    <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                        <el-table-column type="index" align="center" label="序号"></el-table-column>
                        <el-table-column prop="teaherName" label="老师名称" align="center"></el-table-column>
                        <el-table-column prop="teaherCode" label="老师编号" align="center"></el-table-column>
                        <el-table-column  label="是否在职" align="center">
                            <template slot-scope="scope">
                                <span v-if="scope.row.zt=='1'">在职</span>
                                <span v-if="scope.row.zt=='2'">离职</span>
                                <span v-if="scope.row.zt=='3'">休假</span>
                            </template>
                        </el-table-column>
                        <el-table-column prop="teaherAge" label="老师年龄" align="center"></el-table-column>
                        <el-table-column  label="老师性别" align="center">
                            <template slot-scope="scope">
                                <span v-if="scope.row.teaherSex=='1'">男</span>
                                <span v-if="scope.row.teaherSex=='2'">女</span>
                            </template>
                        </el-table-column>
                        <el-table-column  label="老师部门" align="center">
                            <template slot-scope="scope">
                                <span v-if="scope.row.teaherDid=='1'">大数据</span>
                                <span v-if="scope.row.teaherDid=='2'">全栈</span>
                            </template>
                        </el-table-column>
                        <el-table-column prop="teaherBirthday" label="出生日期" align="center"></el-table-column>
                        <el-table-column label="老师头像" align="center">
                            <template slot-scope="scope">
                                <img :src="scope.row.teaherImg" width="100px" height="60px">
                            </template>
                        </el-table-column>
                        <el-table-column  label="爱好" align="center">
                            <template slot-scope="scope">
                                <span v-if="scope.row.hobby.includes ('1')">抽烟</span>
                                <span v-if="scope.row.hobby.includes ('2')">喝酒</span>
                                <span v-if="scope.row.hobby.includes ('3')">烫头</span>
                            </template>
                        </el-table-column>
                        <el-table-column label="操作" align="center">
                            <template slot-scope="scope">
                                <el-button type="primary" size="mini" @click="handleYes(scope.row)">通过</el-button>
                                <el-button type="primary" size="mini" @click="handleNo(scope.row)">拒绝</el-button>
                                <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">编辑</el-button>
                                <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    <div class="pagination-container">
                        <el-pagination
                            class="pagiantion"
                            @current-change="handleCurrentChange"
                            :current-page="pagination.currentPage"
                            :page-size="pagination.pageSize"
                            layout="total, prev, pager, next, jumper"
                            :total="pagination.total">
                        </el-pagination>
                    </div>
                    <!-- 新增标签弹层 -->
                    <div class="add-form">
                        <el-dialog title="新增" :visible.sync="dialogFormVisible">
                            <template>
                                <el-tabs v-model="activeName" type="card">
                                    <el-tab-pane label="基本信息" name="first">
                                        <el-form ref="dataAddForm" :model="formData" :rules="rules" label-position="right" label-width="100px">
                                            <el-row>
                                                <el-col :span="24">
                                                    <el-form-item label="所属校区" prop="sid">
                                                        <el-select v-model="formData.did"  placeholder="请选择校区">
                                                            <el-option v-for="c in tableData" :label="c.name" :value="c.id+''"></el-option>
                                                        </el-select>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item label="老师名称" prop="teaherName">
                                                        <el-input v-model="formData.teaherName"/>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item label="老师编号" prop="teaherCode">
                                                        <el-input v-model="formData.teaherCode"/>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                            <el-row>
                                                <el-col :span="24">
                                                    <el-form-item label="是否在职" prop="zt">
                                                        <el-radio-group v-model="formData.zt" >
                                                            <el-radio label="1">在职</el-radio>
                                                            <el-radio label="2">离职</el-radio>
                                                            <el-radio label="3">休假</el-radio>
                                                        </el-radio-group>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item label="老师年龄" prop="teaherAge">
                                                        <el-input type="number" v-model="formData.teaherAge"/>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item label="老师性别">
                                                        <el-radio-group v-model="formData.teaherSex" >
                                                            <el-radio label="1">男</el-radio>
                                                            <el-radio label="2">女</el-radio>
                                                        </el-radio-group>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item label="老师部门" prop="did">
                                                        <el-select v-model="formData.did"  placeholder="请选择校区">
                                                            <el-option label="大数据" value="1"></el-option>
                                                            <el-option label="全栈" value="2"></el-option>
                                                        </el-select>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item label="出生日期" prop="studentBirthday">
                                                        <el-date-picker v-model="formData.studentBirthday"  type="date" placeholder="选择日期"  style="width: 100%;"></el-date-picker>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                            <el-row>
                                                <el-col :span="24">
                                                    <el-form-item label="老师爱好" prop="hobby">
                                                        <el-checkbox-group v-model="formData.hobby">
                                                            <el-checkbox label="1">抽烟</el-checkbox>
                                                            <el-checkbox label="2">喝酒</el-checkbox>
                                                            <el-checkbox label="3">烫头</el-checkbox>
                                                        </el-checkbox-group>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                            <el-row>
                                                <el-col :span="24">
                                                    <el-form-item label="老师头像">
                                                        <el-upload action="/two/upload.do"
                                                                   name="imgFile"
                                                                   :show-file-list="false"
                                                                   :on-success="handleSuccess"
                                                                   :before-upload="beforeUpload">
                                                            <el-button type="primary">上传文件</el-button>
                                                        </el-upload>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                        </el-form>
                                    </el-tab-pane>
                                </el-tabs>
                            </template>
                            <div slot="footer" class="dialog-footer">
                                <el-button @click="dialogFormVisible = false">取消</el-button>
                                <el-button type="primary" @click="handleAdd()">确定</el-button>
                            </div>
                        </el-dialog>
                    </div>

                    <!-- 编辑标签弹层 -->
                    <div class="add-form">
                        <el-dialog title="编辑" :visible.sync="dialogFormVisible4Edit">
                            <template>
                                <el-tabs v-model="activeName" type="card">
                                    <el-tab-pane label="基本信息" name="first">
                                        <el-form ref="dataEditForm" :model="formData" :rules="rules" label-position="right" label-width="100px">
                                                <el-row>
                                                    <el-col :span="24">
                                                        <el-form-item label="所属校区" prop="sid">
                                                            <el-select v-model="formData.did"  placeholder="请选择校区">
                                                                <el-option v-for="c in tableData" :label="c.name" :value="c.id+''"></el-option>
                                                            </el-select>
                                                        </el-form-item>
                                                    </el-col>
                                                </el-row>
                                                <el-row>
                                                    <el-col :span="12">
                                                        <el-form-item label="老师名称" prop="teaherName">
                                                            <el-input v-model="formData.teaherName"/>
                                                        </el-form-item>
                                                    </el-col>
                                                    <el-col :span="12">
                                                        <el-form-item label="老师编号" prop="teaherCode">
                                                            <el-input v-model="formData.teaherCode"/>
                                                        </el-form-item>
                                                    </el-col>
                                                </el-row>
                                                <el-row>
                                                    <el-col :span="24">
                                                        <el-form-item label="是否在职" prop="zt">
                                                            <el-radio-group v-model="formData.zt" >
                                                                <el-radio label="1">在职</el-radio>
                                                                <el-radio label="2">离职</el-radio>
                                                                <el-radio label="3">休假</el-radio>
                                                            </el-radio-group>
                                                        </el-form-item>
                                                    </el-col>
                                                </el-row>
                                                <el-row>
                                                    <el-col :span="12">
                                                        <el-form-item label="老师年龄" prop="teaherAge">
                                                            <el-input type="number" v-model="formData.teaherAge"/>
                                                        </el-form-item>
                                                    </el-col>
                                                    <el-col :span="12">
                                                        <el-form-item label="老师性别">
                                                            <el-radio-group v-model="formData.teaherSex" >
                                                                <el-radio label="1">男</el-radio>
                                                                <el-radio label="2">女</el-radio>
                                                            </el-radio-group>
                                                        </el-form-item>
                                                    </el-col>
                                                </el-row>
                                                <el-row>
                                                    <el-col :span="12">
                                                        <el-form-item label="老师部门" prop="did">
                                                            <el-select v-model="formData.did"  placeholder="请选择校区">
                                                                <el-option label="大数据" value="1"></el-option>
                                                                <el-option label="全栈" value="2"></el-option>
                                                            </el-select>
                                                        </el-form-item>
                                                    </el-col>
                                                    <el-col :span="12">
                                                        <el-form-item label="出生日期" prop="studentBirthday">
                                                            <el-date-picker v-model="formData.studentBirthday"  type="date" placeholder="选择日期"  style="width: 100%;"></el-date-picker>
                                                        </el-form-item>
                                                    </el-col>
                                                </el-row>
                                                <el-row>
                                                    <el-col :span="24">
                                                        <el-form-item label="老师爱好" prop="hobby">
                                                            <el-checkbox-group v-model="formData.hobby">
                                                                <el-checkbox label="1">抽烟</el-checkbox>
                                                                <el-checkbox label="2">喝酒</el-checkbox>
                                                                <el-checkbox label="3">烫头</el-checkbox>
                                                            </el-checkbox-group>
                                                        </el-form-item>
                                                    </el-col>
                                                </el-row>
                                                <el-row>
                                                    <el-col :span="24">
                                                        <el-form-item label="老师头像">
                                                            <el-upload action="/two/upload.do"
                                                                       name="imgFile"
                                                                       :show-file-list="false"
                                                                       :on-success="handleSuccess"
                                                                       :before-upload="beforeUpload">
                                                                <el-button type="primary">上传文件</el-button>
                                                            </el-upload>
                                                        </el-form-item>
                                                    </el-col>
                                                </el-row>
                                        </el-form>
                                    </el-tab-pane>
                                </el-tabs>
                            </template>
                            <div slot="footer" class="dialog-footer">
                                <el-button @click="dialogFormVisible4Edit = false">取消</el-button>
                                <el-button type="primary" @click="handleEdit()">确定</el-button>
                            </div>
                        </el-dialog>
                    </div>

                    <!-- 编辑标签弹层 -->
                    <el-dialog title="总金额统计" :visible.sync="dialogFormVisible4Echarts">
                        <div id="chart1" style="height:400px;"></div>
                        <div slot="footer" class="dialog-footer">
                            <el-button @click="dialogFormVisible4Echarts = false">取消</el-button>
                        </div>
                    </el-dialog>
                </div>
            </div>
        </div>
    </body>

    <script>
        var vue = new Vue({
            el: '#app',
            data:{
                activeName:'first',//添加/编辑窗口Tab标签名称
                pagination: {//分页相关属性
                    currentPage: 1,//当前页码
                    pageSize:5,//每页显示的记录数
                    total:100,//总记录数
                    queryString:null,//查询条件
                },
                dataList: [{teaherName:'测试数据',hobby:["1"]}],//列表数据
                formData: {zt:"1",hobby:[]},//表单数据
                tableData:[],//新增和编辑表单中对应的检查项列表数据
                checkitemIds:[],//新增和编辑表单中检查项对应的复选框，基于双向绑定可以进行回显和数据提交
                dialogFormVisible: false,//控制添加窗口显示/隐藏
                dialogFormVisible4Echarts:false,
                dialogFormVisible4Edit:false,//控制编辑窗口显示/隐藏
                rules: {//校验规则
                    sid: [{ required: true, message: '为必填项', trigger: 'blur' }],
                    teaherName: [{ required: true, message: '为必填项', trigger: 'blur' }],
                    teaherCode: [{ required: true, message: '为必填项', trigger: 'blur' }],
                    zt: [{ required: true, message: '为必填项', trigger: 'blur' }],
                    teaherSex: [{ required: true, message: '为必填项', trigger: 'blur' }],
                    did: [{ required: true, message: '为必填项', trigger: 'blur' }],
                    studentBirthday: [{ required: true, message: '为必填项', trigger: 'blur' }],
                    hobby: [{ required: true, message: '为必填项', trigger: 'blur' }],
                    teaherAge: [{ required: true, min:2,max:5,message: '必须为数字，且长度在2-5', trigger: 'blur' }]
                }
            },
            //钩子函数，VUE对象初始化完成后自动执行
            created() {
                this.findPage();
            },
            methods: {
                //编辑
                handleEdit() {
                    //发送ajax请求，将修改后的表单数据（检查组基本信息、勾选的检查项）提交到后台进行处理
                    this.$refs['dataEditForm'].validate((valid) => {
                        if(valid){
                            // this.formData.hobby = this.formData.hobby.join(",");
                    axios.post("/two/edit.do",this.formData).then((res) => {
                        //关闭编辑窗口
                        this.dialogFormVisible4Edit = false;
                        this.$message({
                            type:res.data.flag?'success':'error',
                            message:res.data.message
                        });
                    }).catch((res)=>{
                        if(res.message.includes("403")) {
                            this.$message.error("无操作权限！")
                        }
                    }).finally(() =>{
                        this.findPage();
                    });
                    }else{
                        //表单校验不通过
                        this.$message.error("数据校验失败，请检查你的输入信息是否正确！");
                        return false;
                    }
                    });
                },
                //添加
                handleAdd () {
                    //alert(this.checkitemIds);
                this.$refs['dataAddForm'].validate((valid) => { //获取 ref属性是dataEditForm的表单   validate表单检验的方法
                    // valid  描述的表单提交的结果(true  false)  true表单成功校验 false 表单校验失败
                    if(valid){
                    //发送ajax请求，将表单数据提交到后台进行处理
                        // this.formData.hobby = this.formData.hobby.join(",");
                        axios.post("/two/add.do",this.formData).then((res) => {
                            //关闭新增窗口
                            this.dialogFormVisible = false;
                            this.$message({
                                type:res.data.flag?'success':'error',
                                message:res.data.message
                            });
                        }).catch((res)=>{
                            if(res.message.includes("403")) {
                                this.$message.error("无操作权限！")
                            }
                        }).finally(() => {
                            //重新进行分页查询
                            this.findPage();
                        });
                    }else{
                        //表单校验不通过
                        this.$message.error("表单数据校验失败!");
                        return false;
                    }
                    });
                },
                //分页查询
                findPage() {
                    //发送ajax请求，提交分页相关参数
                    axios.post("/two/findPage.do",this.pagination).then((res) => {
                        //为VUE对象的模型数据赋值，基于双向数据绑定展示到页面
                        this.dataList = res.data.rows;//当前页展示的数据集合
                        this.pagination.total = res.data.total;//总数据量
                    }).catch((res)=>{
                        if(res.message.includes("403")) {
                            this.$message.error("无操作权限！")
                        }
                    });
                },
                // 重置表单
                resetForm() {
                    this.formData = {zt:"1",hobby:[]};
                },
                // 弹出添加窗口
                handleCreate() {
                    this.resetForm();
                    this.dialogFormVisible = true;
                    //发送ajax请求，查询所有的检查项信息，转为json，赋值给tableData
                    this.activeName = 'first';//默认选中first对应的tab
                    this.checkitemIds = [];//重置复选框
                    axios.get("/one/findAll.do").then((res) => {
                        //查询检查项数据成功
                        this.tableData = res.data.data;
                    });
                },
                // 弹出编辑窗口
                handleUpdate(row) {
                    //弹出编辑窗口
                    this.dialogFormVisible4Edit = true;
                    this.activeName = 'first';
                    //用于基本信息的回显
                    this.formData = row;
                    // this.formData.hobby = this.formData.hobby.split(",");
                    //发送ajax请求，查询所有的检查项数据，用于展示检查项列表
                    axios.get("/one/findAll.do").then((res) => {
                        if(res.data.flag){
                            //查询检查项数据成功
                            this.tableData = res.data.data;
                        }else{
                            //查询检查项数据失败
                            this.$message.error(res.data.message);
                        }
                    });
                },
                handleYes(row) {
                    this.$confirm("确定吗？","提示",{//确认框
                        type:'warning'
                    }).then(()=>{
                        //用户点击确定按钮，发送ajax请求，将检查项ID提交到Controller进行处理
                        axios.get("/two/updateYes.do?id=" + row.id).then((res) => { //点击确定执行的操作
                            //重新进行分页查询
                            this.findPage();
                            this.$message({
                                type:res.data.flag?'success':'error',
                                message:res.data.message
                            });
                        }).catch((res)=>{
                            if(res.message.includes("403")) {
                                this.$message.error("无操作权限！")
                            }
                        });
                    }).catch(()=>{ //点击取消执行的操作
                        this.$message({
                            type:'info',
                            message:'操作已取消'
                        });
                    });
                },
                handleNo(row) {
                    this.$confirm("确定吗？","提示",{//确认框
                        type:'warning'
                    }).then(()=>{
                        //用户点击确定按钮，发送ajax请求，将检查项ID提交到Controller进行处理
                        axios.get("/two/updateNo.do?id=" + row.id).then((res) => { //点击确定执行的操作
                            //重新进行分页查询
                            this.findPage();
                            this.$message({
                                type:res.data.flag?'success':'error',
                                message:res.data.message
                            });
                        }).catch((res)=>{
                            if(res.message.includes("403")) {
                                this.$message.error("无操作权限！")
                            }
                        });
                    }).catch(()=>{ //点击取消执行的操作
                        this.$message({
                            type:'info',
                            message:'操作已取消'
                        });
                    });
                },
                //上传之前进行文件格式校验
                beforeUpload(file){
                    return true;
                },
                //上传成功提示
                handleSuccess(response, file) {
                    if(response.flag){
                        this.findPage();
                        this.formData.pic=response.data;
                        this.$message({
                            message: response.message,
                            type: 'success'
                        });
                    }else{
                        this.$message.error(response.message);
                    }
                },
                // 弹出echarts
                countBank() {
                    // 弹框
                    this.dialogFormVisible4Echarts = true;
                    this.$nextTick(() => {
                        axios.get("/two/getCount.do").then((res)=>{
                            // 基于准备好的dom，初始化echarts实例

                            //柱状图、折线图、曲线 x轴y轴都是数组['名称'] [数量]
                            //x轴是数组['名称'] ,y轴[{name:名称,value:数量}]

                            var myChart1 = echarts.init(document.getElementById('chart1'));
                    var option = {
                        title : {
                            text : '初始化完毕，setOption填入数值'
                        },
                        tooltip : {},
                        legend : {
                        },
                        xAxis : {
                            data : xdata
                        },
                        yAxis : {},
                        series : [ {
                            name : "统计信息",
                            type : 'bar',
                            data : ydata
                        } ]
                    };
                    myChart1.setOption(option);
                });
                });
                },
                exportExcel(){
                    window.location.href = '/two/exportReport.do';
                },
                //切换页码
                handleCurrentChange(currentPage) {
                    //为模型数据赋值（当前页面）
                    this.pagination.currentPage = currentPage;
                    this.findPage();
                },
                // 删除
                handleDelete(row) {
                    //先删除中间表
                    //再删除检查组本身
                    //alert(row.id);
                    this.$confirm("你确定要删除当前数据吗？","提示",{//确认框
                        type:'warning'
                    }).then(()=>{
                        //用户点击确定按钮，发送ajax请求，将检查项ID提交到Controller进行处理
                        axios.get("/two/delete.do?id=" + row.id).then((res) => { //点击确定执行的操作
                            if(res.data.flag){
                        //执行成功
                        //弹出成功提示信息
                        this.$message({
                            type:'success',
                            message:res.data.message
                        });
                        //重新进行分页查询
                        this.findPage();
                    }else{
                        //执行失败
                        this.$message.error(res.data.message);
                    }
                }).catch((res)=>{
                            if(res.message.includes("403")) {
                                this.$message.error("无操作权限！")
                            }
                        });
                }).catch(()=>{ //点击取消执行的操作
                        this.$message({
                            type:'info',
                            message:'操作已取消'
                        });
                });
                }
            }
        })
    </script>
</html>
